package com.yjhb.android.sbz.activity;

import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.adapter.ReputationDetailedAdapter;
import com.yjhb.android.sbz.entity.ReputationDetailed;
import com.yjhb.android.sbz.mvp.reputation.ReputationDetailedPresenter;
import com.yjhb.android.sbz.mvp.reputation.ReputationDetailedView;
import com.yjhb.android.sbz.view.RefreshHead;
import com.jojo.android.zxlib.view.EmptyRecyclerView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2021/3/1 16:23
 * 信誉明细
 */
public class ReputationDetailedActivity extends BaseActivity<ReputationDetailedPresenter> implements OnRefreshLoadmoreListener, ReputationDetailedView {
    private final String TAG = "ReputationDetailedActivity";
    @BindView(R.id.back)
    FrameLayout back;
    @BindView(R.id.title_right_tv)
    TextView titleRightTv;
    @BindView(R.id.refreshHeader)
    RefreshHead refreshHeader;
    @BindView(R.id.empty_iv)
    ImageView emptyIv;
    @BindView(R.id.tips_tv)
    TextView tipsTv;
    @BindView(R.id.recyclerView)
    EmptyRecyclerView recyclerView;
    @BindView(R.id.content_layout)
    LinearLayout contentLayout;
    @BindView(R.id.footer)
    BallPulseFooter footer;
    @BindView(R.id.smartRefreshLayout)
    SmartRefreshLayout smartRefreshLayout;

    ReputationDetailedAdapter adapter;

    private final int size = 25;
    private int current = 1;

    List<ReputationDetailed> data = new ArrayList<>();

    @Override
    protected ReputationDetailedPresenter initPresenter() {
        return new ReputationDetailedPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_reputation_detailed;
    }

    @Override
    protected void initUI() {
        recyclerView.setEmptyViewById(R.id.layout_empty);
        adapter = new ReputationDetailedAdapter(this);
        adapter.setData(data);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        loadingDialog.show();
        presenter.getScoreChangeInfo(size, current);
    }

    @Override
    protected void regEvent() {
        smartRefreshLayout.setOnRefreshLoadmoreListener(this);
    }


    @OnClick(R.id.back)
    void back() {
        finish();
    }

    @Override
    public void onLoadmore(RefreshLayout refreshlayout) {
        current++;
        presenter.getScoreChangeInfo(size, current);
    }

    @Override
    public void onRefresh(RefreshLayout refreshlayout) {
        current = 1;
        presenter.getScoreChangeInfo(size, current);
    }

    @Override
    public void onLoad(List<ReputationDetailed> data) {
        loadingDialog.cancel();
        smartRefreshLayout.finishLoadmore();
        if (data != null) {
            this.data.addAll(data);
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onRefresh(List<ReputationDetailed> data) {
        loadingDialog.cancel();
        smartRefreshLayout.finishRefresh();
        if (data != null) {
            this.data.clear();
            this.data.addAll(data);
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onFailure(int code, String msg) {

    }
}
